/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SMART_SERVE_PLUGIN_DUMMY_SESSION_H
#define SMART_SERVE_PLUGIN_DUMMY_SESSION_H

#include <model/adapter.h>
#include <model/creator.h>
#include <session/adapter.h>
#include <session/creator.h>

#include <smart_serve_log.h>

namespace OHOS {
namespace SmartServe {

#define TAG "[DummySessionAdapter] "

class DummySessionAdapter : public SessionAdapter {
public:
    DummySessionAdapter(std::string name) : name_(name)
    {}

    const std::string& Name() const override
    {
        return name_;
    }

    const std::vector<SessionResConfig>& InitialResConfigs() const override
    {
        static std::vector<SessionResConfig> cfgs{
            SessionResConfig{.nCPUs = 1, .memSize_ = 10},
            SessionResConfig{.nCPUs = 1, .memSize_ = 5},
        };
        return cfgs;
    }

    SessionApplyResult ApplyResConfig(const SessionResConfig& target) override
    {
        (void)target;
        SMART_SERVE_LOGD(TAG "%s: ApplyResConfig", name_.c_str());
        return {ApplyResult::SUCCESSFUL, {}};
    }

    SessionEvalResult Eval(EvalTask* _task) override
    {
        SMART_SERVE_LOGD(TAG "%s: Eval", name_.c_str());

        auto task = static_cast<EvalLLMTask*>(_task);

        task->AppendResult("Hello from DummySessionAdapter");
        task->Done(EvalTask::TaskState::FINISHED);

        return {EvalResult::FINISHED, {}};
    }

    void Finalize() override
    {
        SMART_SERVE_LOGD(TAG "%s: Finalize", name_.c_str());
    }

private:
    std::string name_;
};

class DummySessionCreator : public SessionCreator {
public:
    DummySessionCreator(const std::string& name, const std::vector<std::string>& depModels)
        : name_(name), depModels_(depModels)
    {}

    const std::string& Name() const override
    {
        return name_;
    }
    const std::vector<std::string>& DepModels() const override
    {
        return depModels_;
    }

    std::unique_ptr<SessionAdapter> Create(const std::vector<ModelAdapter*>& modelAdapters) override
    {
        for (auto& ma : modelAdapters) {
            SMART_SERVE_LOGD("[DummySessionCreator] Create %s with model %s", name_.c_str(), ma->Name().c_str());
        }

        return std::make_unique<DummySessionAdapter>(name_);
    }

    std::string name_;
    std::vector<std::string> depModels_;
};

#undef TAG

} // namespace SmartServe
} // namespace OHOS

#endif // SMART_SERVE_PLUGIN_DUMMY_SESSION_H